package com.qr.service.wmyw.impl;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.mapping.ResultMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.krui.helper.db.DBHelper;
import cn.krui.helper.db.DataPage;
import com.qr.bean.wmyw.QrGoods;
import com.qr.bean.wmyw.QrGoodsView;
import com.qr.controller.WmywBase;
import com.qr.mapper.wmyw.QrGoodsMapper;
import com.qr.mapper.wmyw.QrGoodsMapperView;
import com.qr.service.wmyw.QrGoodsService;
//import org.apache.dubbo.config.annotation.Service;

/**
 * @author: zc
 * email: zc8023zs@163.com
 * create_time: 2020/8/13 10:22:54
 */
@Service
//@Service(version = "1.0.0",group="dubbo")
public class QrGoodsServiceImpl implements QrGoodsService{
    @Autowired
    private QrGoodsMapper qrGoodsMapper;

    @Autowired
    private QrGoodsMapperView qrGoodsMapperView;
    
    @Autowired
    private DBHelper dbHelper;

    /**
     * 构造查询条件
     */
    private QueryWrapper<QrGoods> InitWrapper(QrGoods where){
        QueryWrapper<QrGoods> whereWrapper = new QueryWrapper<QrGoods>();
        if(where.getGoods_id()!=null){
			whereWrapper.eq("goods_id",where.getGoods_id());
		}
        if(where.getOc_id()!=null){
			whereWrapper.eq("oc_id",where.getOc_id());
		}
        if(where.getShop_id()!=null){
			whereWrapper.eq("shop_id",where.getShop_id());
		}
        if(where.getCategory_id()!=null){
			whereWrapper.eq("category_id",where.getCategory_id());
		}
        if(where.getName()!=null){
			whereWrapper.eq("name",where.getName());
		}
        if(where.getLogo()!=null){
			whereWrapper.eq("logo",where.getLogo());
		}
        if(where.getMin_buy()!=null){
			whereWrapper.eq("min_buy",where.getMin_buy());
		}
        if(where.getUnit()!=null){
			whereWrapper.eq("unit",where.getUnit());
		}
        if(where.getIntro()!=null){
			whereWrapper.eq("intro",where.getIntro());
		}
        if(where.getDescription()!=null){
			whereWrapper.eq("description",where.getDescription());
		}
        if(where.getTags()!=null){
			whereWrapper.eq("tags",where.getTags());
		}
        if(where.getCreate_time()!=null){
			whereWrapper.eq("create_time",where.getCreate_time());
		}
        if(where.getUnsend()!=null){
			whereWrapper.eq("unsend",where.getUnsend());
		}
        if(where.getStatus()!=null){
			whereWrapper.eq("status",where.getStatus());
		}
        if(where.getRpt_like()!=null){
			whereWrapper.eq("rpt_like",where.getRpt_like());
		}
        if(where.getRpt_favorite()!=null){
			whereWrapper.eq("rpt_favorite",where.getRpt_favorite());
		}
        if(where.getRpt_star0_cnt()!=null){
			whereWrapper.eq("rpt_star0_cnt",where.getRpt_star0_cnt());
		}
        if(where.getRpt_star1_cnt()!=null){
			whereWrapper.eq("rpt_star1_cnt",where.getRpt_star1_cnt());
		}
        if(where.getRpt_star2_cnt()!=null){
			whereWrapper.eq("rpt_star2_cnt",where.getRpt_star2_cnt());
		}
        if(where.getRpt_star3_cnt()!=null){
			whereWrapper.eq("rpt_star3_cnt",where.getRpt_star3_cnt());
		}
        if(where.getRpt_star4_cnt()!=null){
			whereWrapper.eq("rpt_star4_cnt",where.getRpt_star4_cnt());
		}
        if(where.getRpt_star5_cnt()!=null){
			whereWrapper.eq("rpt_star5_cnt",where.getRpt_star5_cnt());
		}
        if(where.getRpt_comment()!=null){
			whereWrapper.eq("rpt_comment",where.getRpt_comment());
		}
        if(where.getVersion_id()!=null){
			whereWrapper.eq("version_id",where.getVersion_id());
		}
        return whereWrapper;
    }

    private QueryWrapper<QrGoodsView> InitWrapperView(QrGoodsView where){
        QueryWrapper<QrGoodsView> whereWrapper = new QueryWrapper<QrGoodsView>();
        if(where.getGoods_id()!=null){
			whereWrapper.eq("goods_id",where.getGoods_id());
		}
        if(where.getOc_id()!=null){
			whereWrapper.eq("oc_id",where.getOc_id());
		}
        if(where.getShop_id()!=null){
			whereWrapper.eq("shop_id",where.getShop_id());
		}
        if(where.getCategory_id()!=null){
			whereWrapper.eq("category_id",where.getCategory_id());
		}
        if(where.getName()!=null){
			whereWrapper.eq("name",where.getName());
		}
        if(where.getLogo()!=null){
			whereWrapper.eq("logo",where.getLogo());
		}
        if(where.getMin_buy()!=null){
			whereWrapper.eq("min_buy",where.getMin_buy());
		}
        if(where.getUnit()!=null){
			whereWrapper.eq("unit",where.getUnit());
		}
        if(where.getIntro()!=null){
			whereWrapper.eq("intro",where.getIntro());
		}
        if(where.getDescription()!=null){
			whereWrapper.eq("description",where.getDescription());
		}
        if(where.getTags()!=null){
			whereWrapper.eq("tags",where.getTags());
		}
        if(where.getCreate_time()!=null){
			whereWrapper.eq("create_time",where.getCreate_time());
		}
        if(where.getUnsend()!=null){
			whereWrapper.eq("unsend",where.getUnsend());
		}
        if(where.getStatus()!=null){
			whereWrapper.eq("status",where.getStatus());
		}
        if(where.getRpt_like()!=null){
			whereWrapper.eq("rpt_like",where.getRpt_like());
		}
        if(where.getRpt_favorite()!=null){
			whereWrapper.eq("rpt_favorite",where.getRpt_favorite());
		}
        if(where.getRpt_star0_cnt()!=null){
			whereWrapper.eq("rpt_star0_cnt",where.getRpt_star0_cnt());
		}
        if(where.getRpt_star1_cnt()!=null){
			whereWrapper.eq("rpt_star1_cnt",where.getRpt_star1_cnt());
		}
        if(where.getRpt_star2_cnt()!=null){
			whereWrapper.eq("rpt_star2_cnt",where.getRpt_star2_cnt());
		}
        if(where.getRpt_star3_cnt()!=null){
			whereWrapper.eq("rpt_star3_cnt",where.getRpt_star3_cnt());
		}
        if(where.getRpt_star4_cnt()!=null){
			whereWrapper.eq("rpt_star4_cnt",where.getRpt_star4_cnt());
		}
        if(where.getRpt_star5_cnt()!=null){
			whereWrapper.eq("rpt_star5_cnt",where.getRpt_star5_cnt());
		}
        if(where.getRpt_comment()!=null){
			whereWrapper.eq("rpt_comment",where.getRpt_comment());
		}
        if(where.getVersion_id()!=null){
			whereWrapper.eq("version_id",where.getVersion_id());
		}
        return whereWrapper;
    }

    /**
     * 门店商品新增
     * @param model 门店商品实体
     * @return 影响行数
     */
	@Override
    public Integer add(QrGoods model){
        return qrGoodsMapper.insert(model);
    }

    /**
     * 门店商品修改byid
     * @param model 门店商品实体
     * @return 影响行数
     */
	@Override
    public Integer update(QrGoods model) {
        return qrGoodsMapper.updateById(model);
    }

    /**
     * 门店商品修改by条件
     * @param model 门店商品实体
     * @param where 门店商品条件
     * @return 影响行数
     */
	@Override
    public Integer update(QrGoods model, Wrapper<QrGoods> where) {
        return qrGoodsMapper.update(model, where);
    }

    /**
     * 门店商品修改by条件-自动封装Wrapper
     * @param model 门店商品实体
     * @return 影响行数
     */
	@Override
    public Integer update(QrGoods model, QrGoods where) {
        Wrapper<QrGoods> wrapper = InitWrapper(where);
        return update(model, wrapper);
    }

    /**
     * 门店商品修改bySQL *version_id = newVersion where version_id = oldVersion
     * @param fields 修改的数据 col1=xx,col2=yy
     * @param where 参数化条件 col1=#{col1}
     * @param params 条件参数 col1=xx
     * @return 影响行数
     */
	@Override
    public Integer update(Map<String, Object> fields, String where, Map<String, Object> params) {
        return dbHelper.update("qr_goods", fields, where, params);
    }

    /**
     * 门店商品删除byid
     * @param id 门店商品主键
     * @return 影响行数
     */
	@Override
    public Integer del(int id) {
        return qrGoodsMapper.deleteById(id);
    }

    /**
     * 门店商品删除by条件
     * @param where 门店商品条件
     * @return 影响行数
     */
	@Override
    public Integer del(Wrapper<QrGoods> where) {
        return qrGoodsMapper.delete(where);
    }

    /**
     * 门店商品删除by条件-自动封装Wrapper
     * @param where 门店商品条件
     * @return 影响行数
     */
    @Override
    public Integer del(QrGoods where) { 
        Wrapper<QrGoods> wrapper = InitWrapper(where);
        return del(wrapper);
    }

    /**
     * 门店商品批量删除byid
     * @param ids 门店商品主键集合
     * @return 影响行数
     */
	@Override
    public Integer del(List<Integer> ids){
        return qrGoodsMapper.deleteBatchIds(ids);
    }

    /**
     * 门店商品批量删除bymap条件
     * @param map 门店商品map条件
     * @return 影响行数
     */
	@Override
    public Integer del(Map<String,Object> map){
        return qrGoodsMapper.deleteByMap(map);
    }

    /**
     * 门店商品详情byid
     * @param id 门店商品主键
     * @return 门店商品详情
     */
	@Override
    public QrGoodsView info(int id){
        return qrGoodsMapperView.selectById(id);
    }

    /**
     * 门店商品详情by条件
     * @param where 门店商品条件
     * @return 门店商品详情
     */
	@Override
    public QrGoodsView info(Wrapper<QrGoodsView> where){
        return qrGoodsMapperView.selectOne(where);
    }

    /**
     * 门店商品详情by条件-自动封装Wrapper
     * @param where 门店商品条件
     * @return 门店商品详情
     */
	@Override
    public QrGoodsView info(QrGoodsView where) {
        Wrapper<QrGoodsView> wrapper = InitWrapperView(where);
        return info(wrapper);
    }

    /**
     * 门店商品详情bySQL
     * @param columns  列名col1,col2,col3^
     * @param where 条件 col1=#{col1}
     * @param params col1:xx
     * @param mappings col1->col1
     * @return
     */
	@Override
    public QrGoods info(String columns, String where, Map<String, Object> params, ResultMapping mappings) {
        return dbHelper.selectOne(columns, "qr_goods", where, params, QrGoods.class, mappings);
    }

    /**
     * 门店商品批量查询byid
     * @param ids 门店商品主键集合
     * @return 门店商品列表
     */
	@Override
    public List<QrGoodsView> select(List<Integer> ids){
        return qrGoodsMapperView.selectBatchIds(ids);
    }

    /**
     * 门店商品批量查询by条件
     * @param where 门店商品条件
     * @return 门店商品列表
     */
	@Override
    public List<QrGoodsView> select(Wrapper<QrGoodsView> where){
        return qrGoodsMapperView.selectList(where);
    }

    /**
     * 门店商品批量查询by条件-自动封装Wrapper
     * @param where 门店商品条件
     * @return 门店商品列表
     */
    @Override
    public List<QrGoodsView> select(QrGoodsView where) {
        Wrapper<QrGoodsView> wrapper = InitWrapperView(where);		
        return select(wrapper);
    }

    /**
     * 门店商品批量查询bymap条件
     * @param map 门店商品map条件
     * @return 门店商品列表
     */
	@Override
    public List<QrGoodsView> select(Map<String,Object> map){
        return qrGoodsMapperView.selectByMap(map);
    }

    /**
     * 门店商品批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
	@Override
    public IPage<QrGoodsView> select(IPage<QrGoodsView> page, Wrapper<QrGoodsView> where){
        return qrGoodsMapperView.selectPage(page, where);
    }

    /**
     * 门店商品批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
    @Override
    public IPage<QrGoodsView> select(IPage<QrGoodsView> page, QrGoodsView where) {
		Wrapper<QrGoodsView> wrapper = InitWrapperView(where);		
        return select(page, wrapper);
    }

    /**
     * 门店商品查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(Wrapper<QrGoodsView> where){
        return qrGoodsMapperView.selectCount(where);
    }

    /**
     * 门店商品查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(QrGoodsView where){
		Wrapper<QrGoodsView> wrapper = InitWrapperView(where);
        return selectCount(wrapper);
    }

    /**
     * 门店商品批量查询bySQL条件分页
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param orderBy 排序字段
     * @param params 参数化 col1=xx
     * @param pageNumber 分页页码
     * @param pageSize 每页行数
     * @param mappings 查询列和实体映射
     * @return 分页之后的数据含总行数
     */
	@Override
    public DataPage<QrGoodsView> select(String columns, String where, String orderBy, Map<String, Object> params, int pageNumber, int pageSize, ResultMapping mappings){
        return dbHelper.select(columns, "qr_goods", where, orderBy, params, pageNumber, pageSize, QrGoodsView.class,mappings);
    }

    /**
     * 门店商品批量查询bySQL条件
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param params 参数化 col1=xx
     * @param mappings 查询列和实体映射
     * @return 栏目扩展列表
     */
	@Override
    public List<QrGoodsView> select(String columns, String where, Map<String, Object> params, ResultMapping mappings){
        return dbHelper.select(columns,"qr_goods",where,params,QrGoodsView.class,mappings);
    }
}